﻿<%@ WebHandler Language="C#" Class="getCusData" %>

using System;
using System.Web;
using System.Data;

using AMCBO;
using AMCOBJ;

public class getCusData : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        //context.Response.Write("Hello World");
        customer cusBO = new customer();
        common comBO = new common();
        customer_obj cusObj = new customer_obj();
        string output = string.Empty;
        DataTable dt = new DataTable();
        if (!string.IsNullOrEmpty(context.Request.QueryString["cusid"]))
        {
            cusObj.Cus_Guid = new Guid(context.Request.QueryString["cusid"].ToString());
            dt = comBO.loadCustomerByCusGuid(cusObj);
            if (dt.Rows.Count > 0)
            {
                output = "[";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    output += "{\"rowid\":\"" + dt.Rows[i]["cus_guid"] +
                        "\",\"id\":\"" + dt.Rows[i]["cus_id"] +
                        "\",\"name\":\"" + dt.Rows[i]["customerName"] +
                        "\",\"mobile\":\"" + dt.Rows[i]["cus_Mobile"] +
                        "\",\"landline\":\"" + dt.Rows[i]["cus_AltPhone"] +
                        "\",\"email\":\"" + dt.Rows[i]["cus_Email"] +
                        "\",\"address\":\"" + dt.Rows[i]["cus_Address1"].ToString().Replace("\n",", ") +
                        "\",\"city\":\"" + dt.Rows[i]["cus_City"] +
                        "\",\"state\":\"" + dt.Rows[i]["cus_State"] +
                        "\",\"postcode\":\"" + dt.Rows[i]["cus_Postcode"] +
                        "\",\"landmark\":\"" + dt.Rows[i]["landmark"] +
                        "\"},";
                }
                if (output[output.Length - 1] == ',')
                {
                    output = output.Substring(0, output.Length - 1);
                }
                output += "]";

                context.Response.Write(output);
            }
            else
            {
                context.Response.Write("n");
            }
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}